from django.db import models

# Create your models here.
from utils.models import BaseModel


class Classification(BaseModel):
    name = models.CharField(max_length=32, verbose_name='分类名')
    img = models.ImageField(upload_to='img', verbose_name='图片')

    class Meta:
        db_table = 'shop_classify'
        verbose_name_plural = '分类表'

    def __str__(self):
        return self.name


class Category(BaseModel):
    name = models.CharField(max_length=32, verbose_name='分类名')
    category_level = models.IntegerField(choices=((1, '一级分类'), (2, '二级分类'), (3, '三级分类')), default=0,
                                         verbose_name='分类级别')
    img = models.ImageField(upload_to='img', default='/img/sq.png', verbose_name='图标')
    parent = models.ForeignKey(to='self', on_delete=models.CASCADE, null=True, blank=True, verbose_name='父分类',
                                  db_constraint=False)

    class Meta:
        db_table = 'shop_category'
        verbose_name_plural = '商品分类表'

    def __str__(self):
        return self.name
